<?php

namespace app\common\model\Post;

use think\Model;

class Collect extends Model
{
    //标志当前模型操作的是哪张表
    protected $name = "post_collect";

    //开启自动写入
    protected $autoWriteTimestamp = true;

    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'createtime_text',
    ];

    // 时间获取器方法
    public function getCreateTimeTextAttr($value, $data)
    {
        // 获取时间
        $createtime = isset($data['createtime']) ? trim($data['createtime']) : '';

        // 判断是否为空，不为空就转换为时间戳
        if (empty($createtime)) {
            return '';
        }
        return date('Y-m-d H:i', $createtime);
    }

    public function post()
    {
        return $this->belongsTo('app\common\model\Post\Post', 'postid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function business()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
